package com.ss.ttm.player;

import android.content.Context;
import android.media.MediaPlayer;
import android.net.Uri;
import android.view.Surface;
import android.view.SurfaceHolder;

import com.ss.ttvideoengine.TTVideoEngine;
import com.ss.ttvideoengine.d.TTVideoError;

import java.io.IOException;
import java.lang.ref.WeakReference;
import java.util.Map;

public interface IMediaPlayerClient {
    public final class OnBufferingUpdateListener {
        private WeakReference<TTVideoEngine> mTTVideoEngineRef;

        public OnBufferingUpdateListener(TTVideoEngine ttVideoEngine) {
            this.mTTVideoEngineRef = new WeakReference(ttVideoEngine);
        }

        public final void onBufferingUpdate(int i) {
            TTVideoEngine ttVideoEngine = this.mTTVideoEngineRef.get();
            if (ttVideoEngine != null && TTVideoEngine.getVideoListener(ttVideoEngine) != null) {
                TTVideoEngine.getVideoListener(ttVideoEngine).onBufferingUpdate(i);
            }
        }
    }

    public final class OnCompletionListener {
        private WeakReference a;

        public OnCompletionListener(TTVideoEngine arg2) {

            this.a = new WeakReference(arg2);
        }

        public final void onCompletion() {
            Object v0 = this.a.get();
            if (v0 != null) {
                TTVideoEngine.o(((TTVideoEngine) v0));
                TTVideoEngine.p(((TTVideoEngine) v0));
                TTVideoEngine.onPlaybackStateChanged(((TTVideoEngine) v0), 0);
                TTVideoEngine.c(((TTVideoEngine) v0)).b();
                if (TTVideoEngine.getVideoListener(((TTVideoEngine) v0)) != null) {
                    TTVideoEngine.getVideoListener(((TTVideoEngine) v0)).onCompletion();
                }
            }
        }
    }

    public final class OnErrorListener {
        private WeakReference a;

        public OnErrorListener(TTVideoEngine arg2) {

            this.a = new WeakReference(arg2);
        }

        public final boolean onError(IMediaPlayerClient arg5, int arg6, int arg7) {
            boolean v0_1;
            Object v0 = this.a.get();
            if (v0 == null) {
                v0_1 = false;
            } else {
                TTVideoEngine.o(((TTVideoEngine) v0));
                TTVideoEngine.onPlaybackStateChanged(((TTVideoEngine) v0), 3);
                TTVideoEngine.q(((TTVideoEngine) v0));
                String v2 = arg5.getStringOption(5002);
                String v1 = "kTTVideoErrorDomainVideoOwnPlayer";
                if (arg5.isOsPlayer()) {
                    v1 = "kTTVideoErrorDomainVideoOSPlayer";
                }
                TTVideoEngine.c(((TTVideoEngine) v0), new TTVideoError(v1, arg6, arg7, v2));
                TTVideoEngine.onVideoEngineFailed(((TTVideoEngine) v0), TTVideoEngine.r(((TTVideoEngine) v0)));
                v0_1 = true;
            }

            return v0_1;
        }
    }

    public final class OnInfoListener {
        private WeakReference<TTVideoEngine> mTTVideoEngineRef;

        public OnInfoListener(TTVideoEngine ttVideoEngine) {
            this.mTTVideoEngineRef = new WeakReference(ttVideoEngine);
        }

        public final boolean onInfo(int what) {
            TTVideoEngine ttVideoEngine = this.mTTVideoEngineRef.get();
            if (ttVideoEngine != null) {
                switch (what) {
                    case MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START: {
                        TTVideoEngine.t(ttVideoEngine);
                        return false;
                    }
                    case MediaPlayer.MEDIA_INFO_BUFFERING_START: {
                        TTVideoEngine.u(ttVideoEngine);
                        return false;
                    }
                    case MediaPlayer.MEDIA_INFO_BUFFERING_END: {
                        TTVideoEngine.v(ttVideoEngine);
                        return false;
                    }
                    case MediaPlayer.MEDIA_INFO_NOT_SEEKABLE: {
                        TTVideoEngine.s(ttVideoEngine);
                        return false;
                    }
                }
                return false;
            }
            return false;
        }
    }

    public final class OnPreparedListener {
        private WeakReference<TTVideoEngine> mTTVideoEngineRef;

        public OnPreparedListener(TTVideoEngine ttVideoEngine) {
            this.mTTVideoEngineRef = new WeakReference(ttVideoEngine);
        }

        public final void onPrepared() {
            TTVideoEngine ttVideoEngine = this.mTTVideoEngineRef.get();
            if (ttVideoEngine != null && ttVideoEngine.mMediaPlayerClient != null) {
                ttVideoEngine.retryCount = 0;
                TTVideoEngine.c(ttVideoEngine, (TTVideoError) null);
                TTVideoEngine.setDuration(ttVideoEngine, ttVideoEngine.mMediaPlayerClient.getDuration());
                TTVideoEngine.j(ttVideoEngine);
                if (ttVideoEngine.mVideoListener != null) {
                    ttVideoEngine.mVideoListener.onPrepared();
                }
                if (!TTVideoEngine.k(ttVideoEngine) && (TTVideoEngine.l(ttVideoEngine))) {
                    ttVideoEngine.mMediaPlayerClient.start();
                }

                if (TTVideoEngine.m(ttVideoEngine) == 0) {
                    return;
                }
                TTVideoEngine.seekTo(ttVideoEngine, TTVideoEngine.m(ttVideoEngine));
                TTVideoEngine.n(ttVideoEngine);
            }
        }
    }

    public final class OnSeekCompleteListener {
        private WeakReference a;

        public OnSeekCompleteListener(TTVideoEngine arg2) {

            this.a = new WeakReference(arg2);
        }

        public final void onSeekComplete() {
            Object v0 = this.a.get();
            if (v0 != null) {
                TTVideoEngine.s(((TTVideoEngine) v0));
            }
        }
    }

    public final class OnVideoSizeChangedListener {
        private WeakReference a;

        public OnVideoSizeChangedListener(TTVideoEngine arg2) {

            this.a = new WeakReference(arg2);
        }

        public final void onVideoSizeChanged(int arg3, int arg4) {
            Object v0 = this.a.get();
            if (v0 != null && TTVideoEngine.getVideoListener(((TTVideoEngine) v0)) != null) {
                TTVideoEngine.getVideoListener(((TTVideoEngine) v0)).onVideoSizeChanged(arg3, arg4);
            }
        }
    }

    void setDisplay(SurfaceHolder arg1);

    void setSurface(Surface arg1);

    void release();

    void setVolume(float leftvolume, float rightVolume);

    void seekTo(int arg1);

    void setIntOption(int arg1, int arg2);

    void setDataSource(Context context, Uri uri, Map<String, String> params) throws IllegalArgumentException, SecurityException, IllegalStateException, IOException;

    void setOnBufferingUpdateListener(OnBufferingUpdateListener onBufferingUpdateListener);

    void setOnCompletionListener(OnCompletionListener onCompletionListener);

    void setOnErrorListener(OnErrorListener onErrorListener);

    void setOnInfoListener(OnInfoListener onInfoListener);

    void setOnPreparedListener(OnPreparedListener onPreparedListener);

    void setOnSeekCompleteListener(OnSeekCompleteListener onSeekCompleteListener);

    void setOnVideoSizeChangedListener(OnVideoSizeChangedListener onVideoSizeChangedListener);

    void setIsMute(boolean arg1);

    String getStringOption(int arg1);

    void start();

    long getLongOption(int arg1);

    void pause();

    void reset();

    void stop();

    void prepareAsync();

    int getCurrentPosition();

    int getDuration();

    void disableLooping();

    void setScreenOnWhilePlaying();

    boolean isOsPlayer();

    int getType();
}

